class Forum < ActiveRecord::Base
  has_many :topics
  belongs_to :user, :foreign_key => "user_id"
  belongs_to :last_user,:class_name=>"User", :foreign_key => "last_user_id"
  
  def add_topic(topic)
    self.update_forum(topic.user)
    self.topics_count+=1
    self.save
  end
  
  def delete_topic(topic)
    self.update_forum(topic.user)
    self.topics_count-=1
    self.save
  end
  
  def update_forum(user)
    self.updated_at=Time.now
    self.last_user_id=user.id
    self.save
  end
  
end
